package com.example.user.service.user;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.framework.security.core.util.JwtTokenUtils;
import com.example.user.dal.dataobject.user.UserDO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class AccountServiceImpl implements AccountService {

    @Resource
    private UserService userService;

    @Resource
    private JwtTokenUtils jwtTokenUtils;

    @Override
    public boolean deleteAccount(String userId) {
        boolean remove = userService.remove(Wrappers.<UserDO>lambdaUpdate()
                .eq(UserDO::getUserId, userId));
        if (remove) {
            log.info("删除账户成功，userId={}", userId);
        }

        // 清除缓存登录态
        jwtTokenUtils.removeToken(userId);

        return remove;
    }
}
